package com.kaka.bus.engine.home.info.opinion;

import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.R;
import com.kaka.bus.base.BaseActivity;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.util.U;

import butterknife.BindView;

/**
 * Created by zhangqi on 2016/10/27.
 */

public class OpinionActivity extends BaseActivity<OpinionPresenter> implements OpinionContract.View {

    @BindView(R.id.toolbar_back)
    ImageView mToolbarBack;
    @BindView(R.id.toolbar_name)
    TextView mToolbarName;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.edt_opinion)
    EditText mEdtOpinion;
    @BindView(R.id.btn_opinion)
    AppCompatButton mBtnOpinion;

    @Override
    protected void initView() {
        super.initView();
        mToolbarBack.setOnClickListener(v -> finish());
        mToolbarName.setText("意见反馈");
    }

    @Override
    protected void initListener() {
        mBtnOpinion.setOnClickListener(v -> {
            String opinion = mEdtOpinion.getText().toString();

            if (TextUtils.isEmpty(opinion))
            {
                showMessage("给点建议吧~");
                return;
            }
            mPresenter.commitOpinion(getUserId(),getToken(),opinion);
        });
    }

    @Override
    public void commitSuccess(HttpWrapper<String> wrapper) {
        if(Constant.SUCCESS_CODE.equals(wrapper.code)){
            U.getSingleDialog(this, "提示", "感谢您的建议!", "退出", () -> finish()).show();
            mEdtOpinion.setText("");
        }else if(Constant.TOKEN_TIMEOUT.equals(wrapper.code)){
            U.tokenOut(this);
        }else{
            showMessage(wrapper.info);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_opinion;
    }

    @Override
    protected boolean needFullScreen() {
        return true;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

}
